﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using Core.Base;
using System.Data;
using ERP.BusinessEntities;
using System.Windows.Forms;

namespace MainApp.Modules.GeneralConfig
{
    public class GeneralConfigModule: BaseModule
    {
        public GeneralConfigModule()
        {
            this.Name = "GeneralConfig";
            entity = new GeneralConfigEntity();
            Init();
        }


        public override void LoadData()
        {
            base.LoadData();

            BSCompanysInfo CompanyInfo = (BSCompanysInfo)AppContext.CompanyCtrl.GetFirstObject();
            if (CompanyInfo == null)
                CompanyInfo = new BSCompanysInfo();

            entity.dicModuleObjects["BSCompanys"] = CompanyInfo;

            UpdateBinding("BSCompanys");
        }

        public override void ActionSave()
        {
            BSCompanysInfo CompanyInfo = (BSCompanysInfo)entity.dicModuleObjects["BSCompanys"];

            if (CompanyInfo != null)
            {
                if (CompanyInfo.ID > 0)
                    AppContext.CompanyCtrl.Update(CompanyInfo);
                else
                    AppContext.CompanyCtrl.CreateObject(CompanyInfo);
            }

            AppContext.LoadCurrentCompanyInfo();

            MessageBox.Show("Save successfuly");
        }
       
    }
}
